package com.xcc.server.demo;

import com.xcc.server.Client;
import com.xcc.server.domains.enums.MessageType;
import com.xcc.server.domains.vo.Message;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: xcc
 * @Date: 2021/2/5 13:41
 * @Description:
 */
public class ClientMain {

    public static void main(String[] args) throws IOException, InterruptedException {
        Client client = new Client();
        client.start("127.0.0.1", 9999);
        Message loginMessage = new Message();
        Map<String, Object> header = new HashMap<String, Object>();
        header.put("token", "123");
        loginMessage.setBody("123");
        loginMessage.setHeader(header);
        loginMessage.setMessageType(MessageType.LOGIN);
        client.sendMesage(loginMessage); // 登录

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String message = br.readLine();
            Message bodyMessage = new Message();
            bodyMessage.setBody(message);
            bodyMessage.setMessageType(MessageType.BODY);
            client.sendMesage(bodyMessage);
        }
    }
}
